package com.happy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.happy.dao.CourseMapper;
import com.happy.entity.CourseEntity;
import com.happy.service.ICourseService;
import com.happy.util.StateEnum;
import com.happy.util.StateException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: Wuzh
 * @Description:
 * @Date Created in 15:32 2021/1/23
 * @return
 */
@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, CourseEntity> implements ICourseService {

    @Resource
    private CourseMapper courseMapper;

    @Override
    public List<CourseEntity> queryList ( CourseEntity courseEntity ) {
        if ( courseEntity == null ) {
            throw new StateException ( StateEnum.REQUEST_PARAM_EXCE );
        }
        List<CourseEntity> courseEntities = courseMapper.queryList ( courseEntity );
        return courseEntities;
    }

    @Override
    public CourseEntity saveCourse ( CourseEntity courseEntity ) {
        if ( courseEntity == null ) {
            throw new StateException ( StateEnum.REQUEST_PARAM_EXCE );
        }
        int insert = baseMapper.insert ( courseEntity );
        if ( insert == 0 ) {
            throw new StateException ( StateEnum.INSERT_EXCE );
        }
        return courseEntity;
    }
}
